package tests.utils;

import java.util.List;
import java.util.Vector;

import misc.Seria;

import org.junit.Test;

import utils.math.MathCodes;

public class AitkeinAndRichardsonTest {
    
    
    @Test
    public void aitkeinTest(){
	
	
	Seria Yn = new Seria(){
	    @Override
	    public double getElement(int index) {
		
		double result = 0;
		for (int i = 1; i <= index ; i++){
		    
		    result += (1.0 / (2.0 * i - 1.0)) * Math.pow(1.0 / 3.0, 2.0 * i - 1.0) ; 
		}
		return result;
	    }
	};
		
	double tolerance = 0.5 * Math.pow(10, -6);
	int stopIndex = 20;
	List<List<Double>> result = MathCodes.calculateAitkeinSeries(Yn, stopIndex, tolerance);
	for (List<Double> l : result) {
	    for (Double d : l) {
		System.out.println(d);
	    }
	}
	Vector<String> labels = new Vector<String>();
	labels.add("Yn");
	labels.add("Eps");
	labels.add("Yn,1");
	MyFile.CreateNewSeriaGraph.createNewSeriaXls("Aitkein", "AtikeinSeria", labels, result, false);
	
    }

    
    
    @Test
    public void richardsonTest(){
	
	int s = 3;
	
	Seria Xn = new Seria(){
	    @Override
	    public double getElement(int index) {
		
		double result = 0;
		for (int i = 1; i <= index ; i++){
		    result += 1.0 / Math.pow(i, 4); 
		}
		return result;
	    }
	};
	
	double tolerance = 0.5 * Math.pow(10, -11);
	int stopIndex = 15;
	
	List<List<Double>> result = MathCodes.calculateRichardsonSeries(Xn,
		stopIndex, s, tolerance);
	Vector<String> labels = new Vector<String>();
	labels.add("Yn");
	labels.add("Eps");
	labels.add("Yn,1");
	MyFile.CreateNewSeriaGraph.createNewSeriaXls("Richardson",
		"RichardsonSeria", labels, result, true);
	
    }
}
